<template>
  <el-dialog
    title="费用"
    :visible.sync="costVisible"
    :append-to-body="true"
    @click.stop="stopClose">
    <el-form ref="costForm">
      <nb-form
        label="活动预算费用"
        required="isMoney"
        v-model="paramModel.budgetCost"
        prop="budgetCost"
      ></nb-form>
      <nb-form
        label="活动实际费用"
        required="isMoney"
        v-model="paramModel.actualCost"
        tips="注：活动实际费用用于计算活动的投入产出比"
        prop="actualCost"
      ></nb-form>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <nb-button large type="plain" @click.stop="costVisible = false">取消</nb-button>
      <nb-button large type="primary" @click.stop="confirmCost">确认</nb-button>
    </div>
  </el-dialog>
</template>

<script>
  import NbForm from '@/components/nb-form.vue'
  import Mixin from '@/common/mixin'
  export default {
    data () {
      return {
        costVisible: false,
        paramModel: {
          id: '',
          budgetCost: '',
          actualCost: ''
        }
      }
    },
    mixins: [Mixin],
    components: {
      NbForm
    },
    props: ['search'],
    methods: {
      stopClose () {
      },
      show (row) {
        this.paramModel.id = row.id
        this.paramModel.budgetCost = row.budgetCost
        this.paramModel.actualCost = row.actualCost
        this.costVisible = !this.costVisible
      },
      confirmCost () {
        let value = this.validator(this.$refs.costForm)
        if (!value) {
          this.$store.dispatch('UPDATE_COST', {param: this.paramModel}).then(res => {
            if (res.success) {
              this.search()
              this.$message.success('活动费用更新成功！')
              this.costVisible = !this.costVisible
              this.$emit('over')
            } else {
              this.$message.error(res.msg)
            }
          })
        }
      }
    },
    mounted () {
    }
  }
</script>

<style lang="scss">

</style>
